<?php
namespace Home\Controller;
use Think\Controller;
class PageController extends Controller {
	public function show(){
		if (!isset($_GET['sign'])) {
			return;
		}

		$sign = addslashes($_GET['sign']);
		$page = M('channel_page')->where("sign='$sign'")->find();
		if (!$page) {
			return;
		}
		$pcModel = M('channel_model')->where("model_id='$page[pc_model]'")->find();
		$moModel = M('channel_model')->where("model_id='$page[mo_model]'")->find();
		$this->assign('page', $page);
		$this->assign('sign', $sign);
		if (isMobile()) {
			if (!$moModel) {
				//此处放置没有手机端页面的标识
				return;
			}
			$this->assign('model', $moModel);
			$this->display($moModel['mobile_path'].'/index');
		}
		else {
			if (!$pcModel) {
				//此处放置没有电脑端页面的标识
				return;
			}
			$this->assign('model', $pcModel);
			$this->display($pcModel['pc_path'].'/index');
		}
	}

	public function qrcode()
	{
		if (!isset($_GET['sign'])) {
			return;
		}
		$sign = addslashes($_GET['sign']);
		echo createQRcode(U('Home/Page/download', "sign=$sign", false, true), 'H', 5);
	}

	public function download()
	{
		if (!isset($_GET['sign'])) {
			return;
		}

		$sign = addslashes($_GET['sign']);
		$page = M('channel_page')->where("sign='$sign'")->find();
		if (!$page) {
			return;
		}
		if (isios()) {
			redirect($page['mo_ios'], 0);
		}
		else {
			redirect($page['mo_andriod'], 0);
		}
	}
}
